#include "BDIODeviceLibSupportBase.h"
#include "BDTestBase.h"
#include "BDTestUtils.h"

#define CIRCLE_RADIUS 50

DECLARE_TEST_VAR(Test_2)
{
	int m_iOverlapTimes = 0;
	int virtualPointX = 0;
	int virtualPointY = 0;
	int add = 10;
	bool oldIsOverlapped = false;
};

DECLARE_TEST_N(Test_2, BDTestBase, 1)

DECLARE_EXAMPLE(Test_2)
{
	AllocPainterParamShape(2);
	GetPainterParamShape(0)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(0)->mutable_circle()->set_x(m_iGazePointX);
	GetPainterParamShape(0)->mutable_circle()->set_y(m_iGazePointY);
	GetPainterParamShape(0)->mutable_circle()->set_r(CIRCLE_RADIUS);
	GetPainterParamShape(0)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(0)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_WHITE);

	GetPainterParamShape(1)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
	GetPainterParamShape(1)->mutable_circle()->set_x(TEST_VAR(virtualPointX));
	GetPainterParamShape(1)->mutable_circle()->set_y(TEST_VAR(virtualPointY));
	GetPainterParamShape(1)->mutable_circle()->set_r(CIRCLE_RADIUS);
	GetPainterParamShape(1)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
	GetPainterParamShape(1)->mutable_circle()->set_fill_color(PainterRefreshParam_Shape_Color_COLOR_WHITE);

	TEST_VAR(virtualPointX) += 10;
	TEST_VAR(virtualPointY) += 10;

	if (TEST_VAR(virtualPointX) == 500) {
		TEST_VAR(virtualPointX) = 0;
		TEST_VAR(virtualPointY) = 0;
	}

	bool newIsOverlapped = BDTestUtils::CalculateOverlap(m_iGazePointX, m_iGazePointY, TEST_VAR(virtualPointX), TEST_VAR(virtualPointY), CIRCLE_RADIUS);
	if (!TEST_VAR(oldIsOverlapped) && newIsOverlapped) {
		TEST_VAR(oldIsOverlapped) = true;
		TEST_VAR(m_iOverlapTimes)++;
	}
	else if (TEST_VAR(oldIsOverlapped) && !newIsOverlapped) {
		TEST_VAR(oldIsOverlapped) = false;
	}

	AllocDetailParamItem(3);
	GetDetailParamItem(0)->set_key("OverlapTimes");
	ostringstream os0;
	os0 << TEST_VAR(m_iOverlapTimes);
	GetDetailParamItem(0)->set_value(os0.str());

	GetDetailParamItem(1)->set_key("GazePoint");
	ostringstream os1;
	os1 << m_iGazePointX << "," << m_iGazePointY;
	GetDetailParamItem(1)->set_value(os1.str());

	GetDetailParamItem(2)->set_key("Attention");
	ostringstream os2;
	os2 << m_iAttention;
	GetDetailParamItem(2)->set_value(os2.str());

	Notify();
}